﻿using System;
using System.Data;
using System.Collections.Generic;
using Maticsoft.Common;
using GPCSC.Model;
using GPCSC.DALFactory;
using GPCSC.IDAL;
namespace GPCSC.BLL
{
    /// <summary>
    /// newsfiletable
    /// </summary>
    public partial class newsfiletable
    {
        private readonly Inewsfiletable dal = DataAccess.Createnewsfiletable();
        public newsfiletable()
        { }
        #region  Method
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(Guid NewsfilesId)
        {
            return dal.Exists(NewsfilesId);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(GPCSC.Model.newsfiletable model)
        {
            return dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(GPCSC.Model.newsfiletable model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(Guid NewsfilesId)
        {

            return dal.Delete(NewsfilesId);
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool DeleteList(string NewsfilesIdlist)
        {
            return dal.DeleteList(NewsfilesIdlist);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public GPCSC.Model.newsfiletable GetModel(Guid NewsfilesId)
        {

            return dal.GetModel(NewsfilesId);
        }

        /// <summary>
        /// 得到一个对象实体，从缓存中
        /// </summary>
        public GPCSC.Model.newsfiletable GetModelByCache(Guid NewsfilesId)
        {

            string CacheKey = "newsfiletableModel-" + NewsfilesId;
            object objModel = Maticsoft.Common.DataCache.GetCache(CacheKey);
            if (objModel == null)
            {
                try
                {
                    objModel = dal.GetModel(NewsfilesId);
                    if (objModel != null)
                    {
                        int ModelCache = Maticsoft.Common.ConfigHelper.GetConfigInt("ModelCache");
                        Maticsoft.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
                    }
                }
                catch { }
            }
            return (GPCSC.Model.newsfiletable)objModel;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return dal.GetList(Top, strWhere, filedOrder);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<GPCSC.Model.newsfiletable> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<GPCSC.Model.newsfiletable> DataTableToList(DataTable dt)
        {
            List<GPCSC.Model.newsfiletable> modelList = new List<GPCSC.Model.newsfiletable>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                GPCSC.Model.newsfiletable model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new GPCSC.Model.newsfiletable();
                    if (dt.Rows[n]["NewsfilesId"] != null && dt.Rows[n]["NewsfilesId"].ToString() != "")
                    {
                        model.NewsfilesId = new Guid(dt.Rows[n]["NewsfilesId"].ToString());
                    }
                    if (dt.Rows[n]["NewsId"] != null && dt.Rows[n]["NewsId"].ToString() != "")
                    {
                        model.NewsId = new Guid(dt.Rows[n]["NewsId"].ToString());
                    }
                    if (dt.Rows[n]["fileUrl"] != null && dt.Rows[n]["fileUrl"].ToString() != "")
                    {
                        model.fileUrl = dt.Rows[n]["fileUrl"].ToString();
                    }
                    if (dt.Rows[n]["IsFirstImage"] != null && dt.Rows[n]["IsFirstImage"].ToString() != "")
                    {
                        model.IsFirstImage = int.Parse(dt.Rows[n]["IsFirstImage"].ToString());
                    }
                    if (dt.Rows[n]["YfileName"] != null && dt.Rows[n]["YfileName"].ToString() != "")
                    {
                        model.YfileName = dt.Rows[n]["YfileName"].ToString();
                    }
                    if (dt.Rows[n]["xfileName"] != null && dt.Rows[n]["xfileName"].ToString() != "")
                    {
                        model.xfileName = dt.Rows[n]["xfileName"].ToString();
                    }
                    if (dt.Rows[n]["filetype"] != null && dt.Rows[n]["filetype"].ToString() != "")
                    {
                        model.filetype = dt.Rows[n]["filetype"].ToString();
                    }
                    if (dt.Rows[n]["TJdate"] != null && dt.Rows[n]["TJdate"].ToString() != "")
                    {
                        model.TJdate = DateTime.Parse(dt.Rows[n]["TJdate"].ToString());
                    }
                    if (dt.Rows[n]["IsDel"] != null && dt.Rows[n]["IsDel"].ToString() != "")
                    {
                        model.IsDel = int.Parse(dt.Rows[n]["IsDel"].ToString());
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        //{
        //return dal.GetList(PageSize,PageIndex,strWhere);
        //}

        #endregion  Method
    }
}

